<!DOCTYPE html>
<html lang="zh_CN">

<head>
   <#include "../common/header.ftl">
    <script src="/js/plugins/ckeditor/ckeditor.js"></script>

    <script>
        $(function () {
            $(function () {

                $("#addStrategyBtn").click(function () {
                    $("#editForm").clearForm(true);
                    $("#inputModal").modal("show");
                })
            });

            //保存操作
            $(".saveBtn").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    if (data.success) {
                        window.location.reload();
                    }
                })
            });

            //修改操作
            $(".updateBtn").click(function () {
                var json = $(this).data("json");
                console.log(json);
                if (json) {
                    //攻略文章数据的回显
                    $("#editForm input[name='id']").val(json.id);
                    $("#editForm input[name='title']").val(json.title);
                    $("#editForm input[name='name']").val(json.name);
                    $("#editForm input[name='picture']").val(json.picture);
                    $("#editForm input[name='color']").val(json.color);
                    $("#editForm input[name='size']").val(json.size);
                    $("#editForm input[name='price']").val(json.price);
                    $("#editForm input[name='discountPrice']").val(json.discountPrice);
                    $("#editForm img").attr("src", json.picture);
                    $("#editForm select[name='type']").val(json.type);
                    $("#editForm select[name='status']").val(json.status);
                }
                $("#inputModal").modal("show");
            });
            $('#status').select2();
            $('#status').select2({
                //当没有选择数据时,显示内容
                placeholder: '请选择所属状态',
                //当存在数据时,显示清楚按钮
                allowClear: true
            });
            $('#type').select2();
            $('#type').select2({
                //当没有选择数据时,显示内容
                placeholder: '请选择所属类型',
                //当存在数据时,显示清楚按钮
                allowClear: true
            });
        });

    </script>
    <style>
        .select2 {
            width: 150px;
        }

        .select2 > span {
            width: 100% !important;
        }
    </style>
</head>
<body>
<!--模态框-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">编辑/添加</h4>
            </div>
            <div class="modal-body">

                <form class="form-horizontal" action="/commodity/saveOrUpdate.do" method="post"
                      id="editForm" enctype="multipart/form-data">
                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img src="#" width="100px">
                            <input type="hidden" class="form-control" name="picture">
                            <input type="file" class="form-control" name="pic">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">商品标题:</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">商品名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">商品颜色：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="color">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">商品尺寸：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="size">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">价格：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="price">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">打折价格：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="discountPrice">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="status">
                                <option value="1">正常</option>
                                <option value="2">新款</option>
                                <option value="3">流行</option>
                                <option value="4">热门</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">类型：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="type">
                                <option value="1">旅游特色衣物</option>
                                <option value="2">旅游网红打卡食品</option>
                                <option value="3">旅游必买小挂饰</option>
                            </select>
                        </div>
                    </div>
                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary saveBtn">保存</button>
            </div>
        </div>
    </div>
</div>


<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
        <#--设置当前要回显当前菜单,必须在载人菜单前完成设置-->
            <#assign menu = "commodity" >
           <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">商品管理</h1>
                </div>
            </div>

            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/commodity/list.do" method="post">
                <input type="hidden" id="currentPage" name="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题/副标题">
                </div>
                <label>状态</label>
                <div class="form-group select2">
                    <select class="form-control form-control-chosen fa fa-search" id="status" name="status">
                        <option value="1">正常</option>
                        <option value="2">新款</option>
                        <option value="3">流行</option>
                        <option value="4">热门</option>
                    </select>
                    <script>
                        $("#status").val(${qo.status});
                    </script>
                </div>
                <label>类型</label>
                <div class="form-group select2">
                    <select class="form-control form-control-chosen fa fa-search" id="type" name="type">
                        <option value="1">旅游特色衣物</option>
                        <option value="2">旅游网红打卡食品</option>
                        <option value="3">旅游必买小挂饰</option>
                    </select>
                    <script>
                        $("#type").val(${qo.type});
                    </script>
                </div>
                <button type="submit" class="btn btn-primary" id="commodityBtn">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a href="javascript:;" class="btn btn-success" id="addStrategyBtn">添加商品</a>
            </form>


            <table class="table table-striped table-hover">
                <tr>
                    <th width="100px">商品图片</th>
                    <th>商品标题</th>
                    <th>商品名称</th>
                    <th>商品颜色</th>
                    <th>商品尺寸</th>
                    <th>创建时间</th>
                    <th>价格</th>
                    <th>打折价格</th>
                    <th>状态</th>
                    <th>类型</th>
                    <th>操作</th>
                </tr>
                <!--如果result不为空就迭代输出-->
                    <#if result??>
                        <#list result.list as entity>
                        <tr>
                            <td><img src="${(entity.picture)!}" width="100px"></td>
                            <td>${(entity.title)!}</td>
                            <td>${(entity.name)!}</td>
                            <td>${(entity.color)!}</td>
                            <td>${(entity.size)!}</td>
                            <td>${(entity.createTime?string("yyyy-MM-dd"))!}</td>
                            <td>${(entity.price)!}</td>
                            <td>${(entity.discountPrice)!}</td>
                            <td>${(entity.statueName)!}</td>
                            <td>${(entity.typeName)!}</td>

                            <td>
                                <a role="button" class="btn btn-info btn-xs updateBtn"
                                   data-json='${entity.json}'>
                                    <span class="glyphicon glyphicon-pencil"></span> 修改
                                </a>
                            </td>
                        </tr>
                        </#list>
                    </#if>
            </table>
            <!--分页-->
            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<script>

</script>

</body>

</html>